

import java.util.*;


public class Goal extends Puzzle {
    private final LinkedList<Cell> cellTestQueue = new LinkedList<Cell>();

    public Goal(String puzzle) {
        super(puzzle);
        this.setupCellTestQueue();
    }

    private void setupCellTestQueue() {
        for (int row = 0; row < this.getRows(); row++) {
            for (int col = 0; col < this.getCols(); col++) {
                final Cell cell = this.getCell(row, col);

                if (cell.isWall() || cell.isEmpty()) { continue; }

                cellTestQueue.add(cell);
            }
        }
    }


    public boolean matches(Puzzle puzzle) {
        for (final Cell goalCell : this.cellTestQueue) {
            final Cell puzzleCell = puzzle.getCell(goalCell.getRow(), goalCell.getCol());

            if (!goalCell.equals(puzzleCell)) {
                return false;
            }
        }

        return true;
    }
}
